package com.powernode.controller;

import com.powernode.domain.ShoppingCart;
import com.powernode.service.ShoppingCartService;
import com.powernode.vo.JwtKey;
import com.powernode.vo.RespResult;
import com.powernode.vo.ResultVO;
import io.jsonwebtoken.JwtBuilder;
import io.jsonwebtoken.Jwts;
import io.jsonwebtoken.SignatureAlgorithm;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.ObjectUtils;
import org.springframework.web.bind.annotation.*;

import java.util.Date;
import java.util.HashMap;
import java.util.List;

/**
 * 购物车控制器
 * 刘冠志
 * 2023/1/10
 */
@RestController
@RequestMapping("/shopcart")
@Api(tags = "购物车管理",value = "提供查询购物车的详细信息的接口")
@CrossOrigin
public class ShopcartController {

    @Autowired
    private ShoppingCartService shoppingCartService;

    @ApiOperation("分页查询购物车接口")
    @ApiImplicitParams({
            @ApiImplicitParam(dataType = "int",name = "userId", value = "用户id",required = true)
    })
    @GetMapping("/list")
    public ResultVO<List<ShoppingCart>> list(int userId , @RequestHeader("token") String token){
        ResultVO<List<ShoppingCart>> resp = new ResultVO<>();

       List<ShoppingCart> list =shoppingCartService.listShoppingCartsByUserId(userId);
        resp.setCode(RespResult.SHOP_YES_CODE);
        resp.setData(list);
        resp.setMsg(token);
        return resp;
    }
}
